﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controller;
using Entity;

namespace Web
{
    public partial class VendorPOList : System.Web.UI.Page
    {
        Helper helper = new Helper();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                VendorPOController vendorPoController = new VendorPOController();
                IList<VendorPOEntity> vendorPoEntities = vendorPoController.FindAllVendorPO();
                VendorPOListGridView.DataSource = vendorPoEntities;
                VendorPOListGridView.DataBind();
            }
            this.PreRender += new EventHandler(UpdateFlashMessage);
        }

        private void UpdateFlashMessage(object sender, EventArgs e)
        {
            helper.ShowFlashMessage(FlashMessageLabel);
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            string poNo = SearchTextBox.Text.Trim();
            VendorPOController VendorPoController = new VendorPOController();
            IList<VendorPOEntity> VendorPoEntities = VendorPoController.FindVendorPOByNo(poNo);
            VendorPOListGridView.DataSource = VendorPoEntities;
            VendorPOListGridView.DataBind();
        }

        protected void SearchButton1_Click(object sender, EventArgs e)
        {
            DateTime fromDate = Convert.ToDateTime(FromTextBox.Text.Trim());
            DateTime toDate = Convert.ToDateTime(ToSearchTextBox.Text.Trim());
            VendorPOController VendorPoController = new VendorPOController();
            IList<VendorPOEntity> VendorPoEntities = VendorPoController.FindVendorPOByDate(fromDate, toDate);
            VendorPOListGridView.DataSource = VendorPoEntities;
            VendorPOListGridView.DataBind();
        }
        protected void VendorPOListGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            VendorPOListGridView.PageIndex = e.NewPageIndex;
            VendorPOController VendorPoController = new VendorPOController();
            IList<VendorPOEntity> VendorPoEntities = VendorPoController.FindAllVendorPO();
            VendorPOListGridView.DataSource = VendorPoEntities;
            VendorPOListGridView.DataBind();

        }
        
    }
}